package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"text/template"
)

// Define a struct to hold the data for the template
type Data struct {
	Name string
	Age  int
}

func main() {
	// Define the data to be used in the template
	data := Data{Name: "John", Age: 30}

	// Define the template string
	templateString := "name: {{.Name}}\nage: {{.Age}}"

	// Create a new template and parse the template string
	tmpl, err := template.New("test").Parse(templateString)
	if err != nil {
		panic(err)
	}

	// Execute the template with the data and store the output in a buffer
	var buf bytes.Buffer
	err = tmpl.Execute(&buf, data)
	if err != nil {
		panic(err)
	}

	// Write the buffer to a YAML file
	err = ioutil.WriteFile("./output.yaml", buf.Bytes(), 0644)
	if err != nil {
		panic(err)
	}

	fmt.Println("YAML file generated successfully!")
}
